package alo.p6.work4;

import alo.p6.BinarySearchTreeNode;

/**
 * @ClassName FindMax
 * @Description 寻找二叉搜索树的最大元素
 * @Author Fanxc
 * @DATE 2021/2/15 9:31
 * @Version 1.0
 */
public class FindMax {
    //递归
    BinarySearchTreeNode findMax(BinarySearchTreeNode root){
        if (root==null){
            return null;
        }else if (root.getRight()==null){
            return root;
        }else {
            return findMax(root.getRight());
        }
    }
    //非递归
    BinarySearchTreeNode findMax2(BinarySearchTreeNode root){
        if (root==null){
            return null;
        }
        while (root.getRight()!=null){
            root=root.getRight();
        }
        return root;
    }
}
